package com.bsi.com.bsi.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.token.TokenService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName LogoutHandler
 * @Author LiuSong
 * @Date 2020/8/13 10:32
 * @Version 1.0
 * @Description 自定义个垃圾退出器，删除下用户
 */
public class LogoutHandlerEx implements LogoutHandler {

    @Autowired
    private InMemoryUserDetailsManager userDetailsService;

    @Override
    public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) {
        userDetailsService.deleteUser(authentication.getName());
    }
}
